<template>
  <div>
    <div style="margin: 10px auto">
      <el-row :gutter="20" v-if="data.singerData.length">
        <el-col :span="5" v-for="item in data.singerData" style="margin-bottom: 40px">
          <div style="text-align: center">
            <img :src="item.singer.avatar" alt="" style="width: 140px; height: 140px; border-radius: 50%; cursor: pointer" @click="router.push('/front/singerDetail?id=' + item.singer.id)">
            <div style="font-size: 18px">{{ item.singer.name }}</div>
          </div>
        </el-col>
      </el-row>
      <div v-else style="margin-top: 100px; text-align: center; font-size: 15px; color: #666666">暂无收藏歌手</div>
      <div v-if="data.total">
        <el-pagination @current-change="loadSingerCollect" layout="total,prev, pager, next" :page-size="data.pageSize" v-model:current-page="data.pageNum" :total="data.total"/>
      </div>
    </div>
  </div>
</template>

<script setup>
import { reactive } from "vue";
import request from "@/utils/request.js";
import {ElMessage} from "element-plus";
import router from "@/router/index.js";

const data = reactive({
  user: JSON.parse(localStorage.getItem('xm-user') || '{}'),
  singerData: [],
  total: 0,
  pageNum: 1,
  pageSize: 8,
})

const loadSingerCollect = () => {
  request.get('/collect/selectPage', {
    params: {
      pageNum: data.pageNum,
      pageSize: data.pageSize,
      userId: data.user.id,
      type: 'SINGER'
    }
  }).then(res => {
    if (res.code === '200') {
      data.singerData = res.data?.list
      data.total = res.data?.total
    } else {
      ElMessage.error(res.msg)
    }
  })
}
loadSingerCollect()

</script>